import Vuex from 'vuex'
import Vue from 'vue'
import user from './modules/user'
import createLogger from 'vuex/dist/logger'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex);

const plugins = [
  createPersistedState({
    key: 'amway-card-store',
    paths: [
      'user'
    ],
    storage: {
      getItem: key => Megalo.getStorageSync(key),
      setItem: (key, value) => Megalo.setStorageSync(key, value),
      removeItem: key => Megalo.removeStorageSync(key)
    }
  }),
];

if(process.env.NODE_ENV !== 'production'){
  plugins.push(createLogger())
}

const store = new Vuex.Store({
  modules: {
    user
  },
  plugins
});

Vue.prototype.$store = store;

export default store;
